#include "mainwidget.h"
#include "mapwidget.h"

#include <QtCore/QDir>
#include <QtGui/QApplication>
#include <QtGui/QLayout>
#include <QTimer>

MainWidget::MainWidget(QWidget *parent)
    : QWidget(parent),
    m_stack(new QStackedWidget(this)),
    m_map(new MapWidget(this))
{
    QHBoxLayout *layout = new QHBoxLayout(this);
    layout->setContentsMargins(0, 0, 0, 0);
    layout->addWidget(m_stack);

    connect(m_map, SIGNAL(close()), this, SIGNAL(close()));
    m_stack->insertWidget(0, m_map);
//    this->parentWidget();



//    QTimer *timer = new QTimer(this);
//    connect(timer, SIGNAL(timeout()), this, SLOT(centerMap()));
//    timer->start(1000);
}

MainWidget::~MainWidget()
{
}

void MainWidget::showMap()
{
    m_stack->setCurrentIndex(0);
}

void MainWidget::showMap(qreal lon, qreal lat)
{
    m_map->centerOnGeoPos(lon, lat);
    showMap();
}

void MainWidget::centerMap(qreal lon, qreal lat)
{
//    this->m_latitude = this->parentWidget()->m_latitude ;
//    this->m_longitude = this->parentWidget()->m_longitude ;
    m_map->centerOnGeoPos(lon , lat);
}

